<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../../header.jsp"%>

<div class="border bg">
<div class="page-header">
	<h2>手机标识查询<small>(<span id="currentCount">0</span>/<span id="totalCount">0</span>)</small></h2>
	<div class="cms_toolbar">
	</div>
</div>

<div class="text-right form-inline">	
	<label class="control-label" for="creator">&nbsp;人员或部门：</label>
	<input type="text" name="creator" id="creator" class="input-small" readonly="readonly" onclick="selectExecutor()" placeholder="请选择部门或人员..."/>	
	
	<button class="btn" onclick="refresh()">查询</button>
</div>

<div>
	<br />
	<table id="listTable" class="table table-striped cms-table">
		<thead>
			<tr>
				<th width="80">姓名</th>
				<th width="90">手机号码</th>
				<th width="120">不同手机信息数</th>
				<th>部门</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	<div class="well cms_more">
		<a href="javascript:;" onclick="moreData()"><i class="icon-arrow-down"></i>查看更多...</a>
	</div>
</div>

</div>

</div>

<table id="listTemplate" class="hide">
  	<tr>
	    <td><a href="" target="blank"></a></td>
	    <td></td>
	    <td></td>
	    <td></td>
  	</tr>
</table>

<script type="text/javascript">
var pageIndex = 0, pageSize = 20, currentCount = 0, totalCount = 0;

function selectExecutor() {
	$.openDialog("#dialog",
			{height:350,
			width:300,
			minHeight:350,
			minWidth:300,
			loadPage:ctx + "/biz/system/user/tree_single.jsp",
			title:"选择部门或人员"},
			function(data) {
				$("#creator").data("id",data.data("id"));
				$("#creator").data("type",data.data("type"));
				$("#creator").val(data.data("name"));
			});
}

function getParameter(){
	return {
		start: pageIndex,
		limit: pageSize,
		userId: $("#creator").data("type") == "user" ? $("#creator").data("id") : "",
		organId: $("#creator").data("type") == "organ" ? $("#creator").data("id") : ""
	};
}

function count(){
	block(".cms_more", "正在加载数据...");
	$.ajax({
    	type: "GET",
    	cache: false,
    	url: ctx + "/biz/system/user/phone/count.json",
    	data: getParameter(),
    	dataType:"json",
    	success:function(json) {
    		unblock(".cms_more");
    		if (!json.succeed) {
    			$.alert(json.message);
    			return;
    		}
    		totalCount = json.data;
			$("#totalCount").text(json.data);
			list();
    	},
		error: function(message) {
			unblock(".cms_more");
			$.alert(message);
		}
	});
}

function list(){
	block(".cms_more", "正在加载数据...");
	$.ajax({
    	type: "GET",
    	cache: false,
    	url: ctx + "/biz/system/user/phone/list.json",
    	data: getParameter(),
    	dataType:"json",
    	success:function(json) {
    		unblock(".cms_more");
    		if (!json.succeed) {
    			$.alert(json.message);
    			return;
    		}
			buildList(json.data);
    	},
		error: function(message) {
			unblock(".cms_more");
			$.alert(message);
		}
	});
}

function refresh(){
	pageIndex = 0;
	currentCount = 0;
	totalCount = 0;
	pageSize = 20;
	
	$("#currentCount").text(currentCount);
	$("#totalCount").text(totalCount);
	$("#listTable").find("tbody").html("");
	$(".cms_more").show();
	count();
	//list();
}

function moreData(){
	pageIndex++;
	list();
}

function buildList(data){
	if(data.length == 0){
		$(".cms_more").hide();
		return;
	}
	currentCount += data.length;
	$("#currentCount").text(currentCount);
	if(currentCount >= totalCount){
		$(".cms_more").hide();
	} else {
		$(".cms_more").show();
	}
	$(data).each(function(index, item) {
		buildTd(item).appendTo($("#listTable").find("tbody"));
	});
}

function buildTd(item){
	var taskEle = $("#listTemplate").clone();
	taskEle.find("tr").attr("id", "item" + item.id);
	var tdList = taskEle.find("td");
	$(tdList.get(0)).find("a").attr("href", ctx + "/biz/system/user/edit.do?id=" + item.id);
	$(tdList.get(0)).find("a").text(item.name);
	$(tdList.get(1)).text(item.mobile);
	$(tdList.get(2)).text(item.phoneCount);
	$(tdList.get(3)).text(item.organName);
	
	return taskEle.find("tr");
}

$(document).ready(function() {
	refresh();
});
</script>

<%@ include file="../../../footer.jsp"%>